package com.woniuxy.caradmin.service.impl;

import com.woniuxy.caradmin.entity.pojo.User;
import com.woniuxy.caradmin.entity.vo.UserVo;
import com.woniuxy.caradmin.mapper.UserMapper;
import com.woniuxy.caradmin.service.UserService;
import org.omg.CORBA.INTERNAL;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;
    @Override
    public List<User> selectAllUser() {
        return userMapper.selectAllUser();
    }

    @Override
    public User selectPhoAndPsw(String telephone, String password) {
        return userMapper.selectPhoAndPsw(telephone,password);
    }

    @Override
    public Integer delectUser(Integer id) {
        return userMapper.delectUser(id);
    }

    @Override
    public Integer insertUser(User user) {
        return userMapper.insertUser(user);
    }

    @Override
    public Integer updateUser(User user) {
        return userMapper.updateUser(user);
    }

    @Override
    public List<User> selectPhoAndName(User user) {
        return userMapper.selectPhoAndName(user);
    }

    @Override
    public Integer empLevel(Integer uid) {
        Integer id = userMapper.empLevel(uid);
        return id;
    }

    @Override
    public User selectOneUser(Integer uid1) {
        return null;
    }

    @Override
    public List<User> selectUserByPage(UserVo userVo) {
        return userMapper.selectPhoAndName(userVo);
    }

    @Override
    public boolean assignRole(Integer[] rids, Integer uid) {
        boolean flag=false;
        this.userMapper.deleteRoleByUid(uid);
        for(Integer rid:rids){
            userMapper.insertUserRole(rid,uid);
        }
        flag =true;
        return flag;
    }

    @Override
    public User selectUserByid(Integer id) {
        return userMapper.selectUserByid(id);
    }

    @Override
    public boolean removePath(Integer[] ids) {
        if (ids!=null&&ids.length>0){
            for(Integer id:ids){
                userMapper.delectUser(id);
            }
        }
        return true;
    }
}
